﻿using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using SAPPDI.Entitys.Annotations;

namespace SAPPDI.Entitys
{
    public class TipoPapel : INotifyPropertyChanged
    {
        private int _ID;
        public int Id
        {
            get { return this._ID; }
            set
            {
                this._ID = value;
                NotifyPropertyChanged("Id");
            }
        }

        private string _nombre;
        public string Nombre
        {
            get { return this._nombre; }
            set
            {
                this._nombre = value;
                NotifyPropertyChanged("Nombre");
            }
        }

        private List<Papel> _papels;

        public List<Papel> Papels
        {
            get { return this._papels; }
            set
            {
                this._papels = value;
                NotifyPropertyChanged("Papels");
            }
        }

        public TipoPapel()
        {
        }

        public TipoPapel(TipoPapel elemento)
        {
            if (elemento == null) return;
            
            this._ID = elemento.Id;
            this._nombre = elemento.Nombre;
            this._papels = new List<Papel>();
            if (elemento.Papels != null)
            {
                foreach (var papel in elemento.Papels)
                {
                    this._papels.Add(new Papel(papel));
                }
            }
        }

        public override string ToString()
        {
            return Nombre;
        }

        public override bool Equals(object obj)
        {
            if (obj == null || typeof(TipoPapel) != obj.GetType())
                return false;
            var elemento = (TipoPapel) obj;
            return this.Nombre == elemento.Nombre && this.Id == elemento.Id;
        }

        public static bool operator ==(TipoPapel a, TipoPapel b)
        {
            // If both are null, or both are same instance, return true.
            if (System.Object.ReferenceEquals(a, b))
            {
                return true;
            }

            // If one is null, but not both, return false.
            if (((object)a == null) || ((object)b == null))
            {
                return false;
            }

            // Return true if the fields match:
            return a.Nombre == b.Nombre && a.Id == b.Id;
        }

        public static bool operator !=(TipoPapel a, TipoPapel b)
        {
            return !(a == b);
        }

        public event PropertyChangedEventHandler PropertyChanged;

        [NotifyPropertyChangedInvocator]
        protected virtual void NotifyPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
